﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region MixProportionDesignDao

        public List<tb_RPT_MixProportionDesign> GetAllMixProportionDesign()
        {
            var query = (from obj in this.tb_RPT_MixProportionDesigns
                         where obj.IsDelete == 0
                         select obj).ToList();
            return query;
        }
        public List<tb_RPT_MixProportionDesign> GetSiteMixProportionDesignBySequence(string strSequence)
        {

            var query = (from obj in this.tb_RPT_MixProportionDesigns
                         where obj.IsDelete == 0 && obj.Sequence == strSequence
                         select obj).ToList();
            return query;
        }
        public List<tb_RPT_MixProportionDesign> GetMixProportionDesignByProjectName(string strProjectName)
        {
             var query = (from obj in this.tb_RPT_MixProportionDesigns
                         where obj.IsDelete == 0 && obj.ProjectName == strProjectName
                         select obj).ToList();
             return query;
        }

        public List<tb_RPT_MixProportionDesign> GetMixProportionDesignByContition(string strProjectName, string strSequence, 
                                                                                  string strStrengthGrade, string strTeststrength,
                                                                                  string strDemandSlump, string strSampleName, 
                                                                                  string strDesignDate)
        {
            var tq = from obj in this.tb_RPT_MixProportionDesigns
                     where obj.IsDelete == 0
                     select obj;

            if (strProjectName.Length > 0)
            {
                tq = tq.Where(entity => entity.ProjectName == strProjectName);
            }
            if (strSequence.Length > 0)
            {
                tq = tq.Where(entity => entity.Sequence == strSequence);
            }
            if (strStrengthGrade.Length > 0)
            {
                tq = tq.Where(entity => entity.StrengthGrade == strStrengthGrade);
            }
            if (strTeststrength.Length > 0)
            {
                tq = tq.Where(entity => entity.Teststrength == strTeststrength);
            }
            if (strDemandSlump.Length > 0)
            {
                tq = tq.Where(entity => entity.DemandSlump == strDemandSlump);
            }
            if (strSampleName.Length > 0)
            {
                tq = tq.Where(entity => entity.SampleName == strSampleName);
            }
            if (strDesignDate.Length > 0)
            {
                tq = tq.Where(entity => entity.DesignDate == strDesignDate);
            } 

            var query = tq.ToList();
            return query;
        }

        public tb_RPT_MixProportionDesign GetMixProportionDesignById(int id)
        {
            return this.tb_RPT_MixProportionDesigns.SingleOrDefault(tb_RPT_MixProportionDesigns => tb_RPT_MixProportionDesigns.Id == id);
        }

        public void CreateMixProportionDesign(tb_RPT_MixProportionDesign entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_RPT_MixProportionDesigns.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifyMixProportionDesign(tb_RPT_MixProportionDesign entity)
        {
            tb_RPT_MixProportionDesign instance = this.tb_RPT_MixProportionDesigns.SingleOrDefault(p => p.Id == entity.Id);
            instance.Sequence = entity.Sequence;
            instance.ProjectName = entity.ProjectName;
            instance.StrengthGrade = entity.StrengthGrade;
            instance.Teststrength = entity.Teststrength;
            instance.DemandSlump = entity.DemandSlump;
            instance.SampleName = entity.SampleName;
            instance.DesignDate = entity.DesignDate;
            instance.CementManufacturers = entity.CementManufacturers;
            instance.AdmixtureName = entity.AdmixtureName;
            instance.StonesOriginTypes = entity.StonesOriginTypes;
            instance.AdmixtureNameModel = entity.AdmixtureNameModel;
            instance.CementFactoryDate = entity.CementFactoryDate;
            instance.AshManufacturer = entity.AshManufacturer;
            instance.StonesNominalSize = entity.StonesNominalSize;
            instance.AdmixtureManufacturer = entity.AdmixtureManufacturer;
            instance.CementVarietiesLab = entity.CementVarietiesLab;
            instance.SandProducingArea = entity.SandProducingArea;
            instance.AdmixtureMixedQuantity = entity.AdmixtureMixedQuantity;
            instance.Admixture = entity.Admixture;
            instance.ProductStrengthGrade = entity.ProductStrengthGrade;
            instance.ProductWaterBinderRatio = entity.ProductWaterBinderRatio;
            instance.ProductSlump = entity.ProductSlump;
            instance.CementPerM = entity.CementPerM;
            instance.SandPerM = entity.SandPerM;
            instance.GravelPerM = entity.GravelPerM;
            instance.WaterPerM = entity.WaterPerM;
            instance.AdmixturePerM = entity.AdmixturePerM;
            instance.AdditivePerM = entity.AdditivePerM;
            instance.ExpansionAgentPerM = entity.ExpansionAgentPerM;
            instance.FiberPerM = entity.FiberPerM;
            instance.TestStandard = entity.TestStandard;
            instance.Remark = entity.Remark;
            instance.Approval = entity.Approval;
            instance.Design = entity.Design;
            instance.Test = entity.Test;
             
            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now;

            this.SubmitChanges();
        }

        public void DeleteMixProportionDesign(tb_RPT_MixProportionDesign entity)
        {
            tb_RPT_MixProportionDesign deleteEntity = tb_RPT_MixProportionDesigns.SingleOrDefault(p => p.Id == entity.Id);
            tb_RPT_MixProportionDesigns.DeleteOnSubmit(deleteEntity);

            this.SubmitChanges();
        }

        #endregion

    }

}
